package lec10.am;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class MovingSmileFace extends JFrame implements MouseListener {
	 int x=0;
	 int dx=100;
	@Override
	public void paint(Graphics g) {
		g.setColor(Color.gray);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(Color.red);
		x+=dx;
		g.drawArc(x+0, 100, 250, 250, 0, 360);
		g.drawArc(x+50, 150, 60, 60, 0, 360);
		g.drawArc(x+140, 150, 60, 60, 0, 360);
		g.drawArc(x+95, 250, 80, 80, 0, -180);
		
	}

	public MovingSmileFace() {
		super("My App");
		setSize(400, 400);
		this.addMouseListener(this);
		setVisible(true);
	}

	public static void main(String[] args) {
		new MovingSmileFace();

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		
		if(x+250>=this.getWidth())
		{
			dx=-dx;
		}else if(x<=0)
			dx=-dx;
		
		
		this.paint(this.getGraphics());
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
}
